<?php
header("Content-type: text/html; charset=utf-8");
require_once("Easemob.class.php");

$easemob_org_name = "zhangdong";
$easemob_app_name = "yidian";
$easemob_app_key = "zhangdong#yidian";
$easemob_client_id = "YXA6de0j0JlaEeWb26GrcCZSyQ";
$easemob_client_secret = "YXA6UIdLDRJ7eU7mSjbmlV6s3PF_8l8";

$options = array(
	"client_id" => $easemob_client_id, 
	"client_secret" => $easemob_client_secret, 
	"org_name" => $easemob_org_name, 
	"app_name" => $easemob_app_name, 
);
$easmob=new Easemob($options);

$i=isset($_GET['i'])?intval($_GET['i']):10;
switch($i){
	case 10://获取token
		$token=$easmob->getToken();
		var_dump($token);
		break;
	case 11://创建单个用户
		echo json_encode($easmob->createUser("zhangsan","123456"));
		break;
	case 12://创建批量用户
		echo json_encode($easmob->createUsers(array(
			array(
				"username"=>"zhangsan",
				"password"=>"123456"
			),
			array(
				"username"=>"lisi",
				"password"=>"123456"
			)
		)));
		break;
	case 13://重置用户密码
		echo json_encode($easmob->resetPassword("zhangsan","123456"));
		break;
	case 14://获取单个用户
		echo json_encode($easmob->getUser("zhangsan"));
		break;
	case 16://获取批量用户
		$cursor=$easmob->getFile("user_cursor.txt");
		echo json_encode($easmob->getUsers(10,$cursor));
		break;
	case 17://删除单个用户
		echo json_encode($easmob->deleteUser("zhangsan"));
		break;
	case 18://删除批量用户
		echo json_encode($easmob->deleteUsers(2));
		break;
	case 19://修改昵称
		echo json_encode($easmob->editNickname("zhangsan","小B"));
		break;
	case 20://添加好友------400
		echo json_encode($easmob->addFriend("zhangsan","lisi"));
		break;
	case 21://删除好友
		echo json_encode($easmob->deleteFriend("zhangsan","lisi"));
		break;
	case 22://查看好友
		echo json_encode($easmob->showFriends("zhangsan"));
		break;
	case 23://查看黑名单
		echo json_encode($easmob->getBlacklist("zhangsan"));
		break;
	case 24://往黑名单中加人
		$usernames=array(
			"usernames"=>array("wangwu","lisi")
		);
		echo json_encode($easmob->addUserForBlacklist("zhangsan",$usernames));
		break;
	case 25://从黑名单中减人
		echo json_encode($easmob->deleteUserFromBlacklist("zhangsan","lisi"));
		break;
	case 26://查看用户是否在线
		echo json_encode($easmob->isOnline("zhangsan"));
		break;
	case 27://查看用户离线消息数
		echo json_encode($easmob->getOfflineMessages("zhangsan"));
		break;
	case 28://查看某条消息的离线状态
		echo json_encode($easmob->getOfflineMessageStatus("zhangsan","77225969013752296_pd7J8-20-c3104"));
		break;
	case 29://禁用用户账号----
		echo json_encode($easmob->deactiveUser("zhangsan"));
		break;
	case 30://解禁用户账号-----
		echo json_encode($easmob->activeUser("zhangsan"));
		break;
	case 31://强制用户下线
		echo json_encode($easmob->disconnectUser("zhangsan"));
		break;
	case 32://上传图片或文件
		echo json_encode($easmob->uploadFile("./resource/up/girl.jpg"));
		//echo json_encode($easmob->uploadFile("./resource/up/mangai.mp3"));
		//echo json_encode($easmob->uploadFile("./resource/up/sunny.mp4"));
		break;
	case 33://下载图片或文件
		echo json_encode($easmob->downloadFile('53008580-7fda-11e6-88f5-93c1766d1cfd', 'UwCFin_aEeaMRaWH6R4-yBYKu4kmb7jkVWYYZn3IJEY0jDIM'));
		break;
	case 34://下载图片缩略图
		echo json_encode($easmob->downloadThumbnail('53008580-7fda-11e6-88f5-93c1766d1cfd','UwCFin_aEeaMRaWH6R4-yBYKu4kmb7jkVWYYZn3IJEY0jDIM'));
		break;
	case 35://发送文本消息
		$from='admin';
		$target_type="users";
		//$target_type="chatgroups";
		$target=array("zhangsan","lisi","wangwu");
		//$target=array("122633509780062768");
		$content="Hello HuanXin!";
		$ext['a']="a";
		$ext['b']="b";
		echo json_encode($easmob->sendText($from,$target,$content,$ext,$target_type));
		break;
	case 36://发送图片消息
		$filepath="./resource/up/pujing.jpg";
		$from='admin';
		$target_type="users";
		$target=array("zhangsan","lisi");
		$filename="pujing.jpg";
		$ext['a']="a";
		$ext['b']="b";
		echo json_encode($easmob->sendImage($from,$target,$filepath,$filename,$ext,$target_type));
		break;
	case 37://发送语音消息
		$filepath="./resource/up/mangai.mp3";
		$from='admin';
		$target_type="users";
		$target=array("zhangsan","lisi");
		$filename="mangai.mp3";
		$ext['a']="a";
		$ext['b']="b";
		echo json_encode($easmob->sendAudio($from,$target,$filepath,$filename,$ext,$target_type));
		break;
	case 38://发送视频消息
		$filepath="./resource/up/sunny.mp4";
		$thumbpath="";
		$from='admin';
		$target_type="users";
		$target=array("zhangsan","lisi");
		$filename="sunny.mp4";
		$ext['a']="a";
		$ext['b']="b";
		echo json_encode($easmob->sendVideo($from,$target,$filepath,$thumbpath,$filename,$ext,$target_type));
		break;
	case 39://发文件消息
		$filepath="./resource/up/a.rar";
		$from='admin';
		$target_type="users";
		$target=array("zhangsan","lisi");
		$filename="a.rar";
		$ext['a']="a";
		$ext['b']="b";
		echo json_encode($easmob->sendFile($from,$target,$filepath,$filename,$ext,$target_type));
		break;
	case 40://发送透传消息
		$from='admin';
		$target_type="users";
		//$target_type="chatgroups";
		$target=array("zhangsan","lisi","wangwu");
		//$target=array("122633509780062768");
		$action="Hello HuanXin!";
		$ext['a']="a";
		$ext['b']="b";
		echo json_encode($easmob->sendCmd($from,$target,$action,$ext,$target_type));
		break;
	case 42:////获取app中的所有群组
		$cursor=$easmob->getFile("group_cursor.txt");
		echo json_encode($easmob->getGroups(2,$cursor));
		break;
	case 43://获取一个或多个群组的详情
		$group_ids=array("1445830526109","1445833238210");
		echo json_encode($easmob->getGroupDetail($group_ids));
		break;
	case 44://创建一个群组
		$options ['groupname'] = "group001";
		$options ['desc'] = "this is a love group";
		$options ['public'] = true;
		$options ['owner'] = "zhangsan";
		$options['members']=Array("fengpei","lisi");
		echo json_encode($easmob->createGroup($options));
		break;
	case 45://修改群组信息
		$group_id="124113058216804760";
		$options['groupname']="group002";
		$options['description']="修改群描述";
		$options['maxusers']=300;
		echo json_encode($easmob->modifyGroupInfo($group_id,$options));
		break;
	case 46://删除群组
		$group_id="124113058216804760";
		echo json_encode($easmob->deleteGroup($group_id));
		break;
	case 47://获取群组中的成员
		$group_id="122633509780062768";
		echo json_encode($easmob->getGroupUsers($group_id));
		break;
	case 48://群组单个加人------
		$group_id="122633509780062768";
		$username="lisi";
		echo json_encode($easmob->addGroupMember($group_id,$username));
		break;
	case 49://群组批量加人
		$group_id="122633509780062768";
		$usernames['usernames']=array("wangwu","lisi");
		echo json_encode($easmob->addGroupMembers($group_id,$usernames));
		break;
	case 50://群组单个减人
		$group_id="122633509780062768";
		$username="test";
		echo json_encode($easmob->deleteGroupMember($group_id,$username));	
		break;
	case 51://群组批量减人-----
		$group_id="122633509780062768";
		//$usernames['usernames']=array("wangwu","lisi");
		$usernames='wangwu,lisi';
		echo json_encode($easmob->deleteGroupMembers($group_id,$usernames));	
		break;
	case 52://获取一个用户参与的所有群组
		echo json_encode($easmob->getGroupsForUser("zhangsan"));
		break;
	case 53://群组转让
		$group_id="122633509780062768";
		$options['newowner']="lisi";
		echo json_encode($easmob->changeGroupOwner($group_id,$options));
		break;
	case 54://查询一个群组黑名单用户名列表
		$group_id="122633509780062768";
		echo json_encode($easmob->getGroupBlackList($group_id));
		break;
	case 55://群组黑名单单个加人-----
		$group_id="122633509780062768";
		$username="lisi";
		echo json_encode($easmob->addGroupBlackMember($group_id,$username));		
		break;
	case 56://群组黑名单批量加人
		$group_id="122633509780062768";
		$usernames['usernames']=array("lisi","wangwu");
		echo json_encode($easmob->addGroupBlackMembers($group_id,$usernames));		
		break;
	case 57://群组黑名单单个减人
		$group_id="122633509780062768";
		$username="lisi";
		echo json_encode($easmob->deleteGroupBlackMember($group_id,$username));		
		break;
	case 58://群组黑名单批量减人
		$group_id="122633509780062768";
		$usernames['usernames']=array("wangwu","lisi");
		echo json_encode($easmob->deleteGroupBlackMembers($group_id,$usernames));		
		break;
	case 59://创建聊天室
		$options ['name'] = "chatroom001";
		$options ['description'] = "this is a love chatroom";
		$options ['maxusers'] = 300;
		$options ['owner'] = "zhangsan";
		$options['members']=Array("man","lisi");
		echo json_encode($easmob->createChatRoom($options));	
		break;
	case 60://修改聊天室信息
		$chatroom_id="124121390293975664";
		$options['name']="chatroom002";
		$options['description']="修改聊天室描述";
		$options['maxusers']=300;
		echo json_encode($easmob->modifyChatRoom($chatroom_id,$options));
		break;
	case 61://删除聊天室
		$chatroom_id="124121390293975664";
		echo json_encode($easmob->deleteChatRoom($chatroom_id));
		break;
	case 62://获取app中所有的聊天室
		echo json_encode($easmob->getChatRooms());
		break;
	case 63://获取一个聊天室的详情
		$chatroom_id="124121939693277716";
		echo json_encode($easmob->getChatRoomDetail($chatroom_id));
		break;
	case 64://获取一个用户加入的所有聊天室
		echo json_encode($easmob->getChatRoomJoined("zhangsan"));
		break;
	case 65://聊天室单个成员添加--
		$chatroom_id="124121939693277716";
		$username="zhangsan";
		echo json_encode($easmob->addChatRoomMember($chatroom_id,$username));
		break;
	case 66://聊天室批量成员添加
		$chatroom_id="124121939693277716";
		$usernames['usernames']=array('wangwu','lisi');
		echo json_encode($easmob->addChatRoomMembers($chatroom_id,$usernames));
		break;
	case 67://聊天室单个成员删除
		$chatroom_id="124121939693277716";
		$username="zhangsan";
		echo json_encode($easmob->deleteChatRoomMember($chatroom_id,$username));
		break;
	case 68://聊天室批量成员删除
		$chatroom_id="124121939693277716";
		//$usernames['usernames']=array('zhangsan','lisi');
		$usernames='zhangsan,lisi';
		echo json_encode($easmob->deleteChatRoomMembers($chatroom_id,$usernames));
		break;
	case 69://导出聊天记录
		//$ql="select+*+where+timestamp>1435536480000";
		$ql="select+*+where+from='162'+and+to='218'+order+by+timestamp+desc";
		$cursor=$easmob->getFile("chat_cursor.txt");
		echo json_encode($easmob->chatRecord($ql,10,$cursor));
		break;
}
